package cn.com.xyc.rabbitmq;

import java.io.IOException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public abstract class EndPoint {
	protected Channel channel;
	protected Connection connection;
	protected String endPointName;

	public EndPoint(String endpointName) throws IOException {
		this.endPointName = endpointName;

		// 创建连接工厂
		ConnectionFactory factory = new ConnectionFactory();
		// rabbit服务器主机名
		factory.setHost("192.168.1.128");
		factory.setUsername("xyc");
		factory.setPassword("123456");
		factory.setPort(5672);
		

		// 创建 connection
		connection = factory.newConnection();

		// 创建 channel
		channel = connection.createChannel();

		channel.queueDeclare(endpointName, false, false, false, null);
	}

	public void close() throws IOException {
		this.channel.close();
		this.connection.close();
	}
}
